home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / apps / math / ols.zoo / valloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-16  |  979 b   |  50 lines

  1. /*
  2. Allocate vector addressed as A[l..r]. E.g., A[1..4] would be
  3.  
  4. 1 2 3 4
  5.  
  6. You would get this vector by calling vector(1, 4).
  7.  
  8. All the work is done by the file "valloc.inc", which creates
  9. vector of type VTYPE.  In this file, we merely tweak VTYPE
  10. several times and include valloc.inc repeatedly.
  11. */
  12.  
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include "utils.h"
  16.  
  17. #define VTYPE float
  18. /* This makes the (fixed) code behave as if it was written
  19.     with float matrices in mind. */
  20. VTYPE *
  21. vector (int l, int h)
  22. #include "valloc.inc"
  23. #undef VTYPE
  24.  
  25. #define VTYPE double
  26.      VTYPE *dvector (int l, int h)
  27. #include "valloc.inc"
  28.      /* That gives us double vectors. */
  29. #undef VTYPE
  30.  
  31. #define VTYPE int
  32.      VTYPE *ivector (int l, int h)
  33. #include "valloc.inc"
  34.      /* That gives us int vectors. */
  35. #undef VTYPE
  36.  
  37. #ifdef TESTING
  38.      int main ()
  39. {
  40.   float *v;
  41.   int i;
  42.  
  43.   for (i = 1; i < 100000; i++)
  44.     v = vector (1, 10);
  45.  
  46.   return 0;
  47. }
  48.  
  49. #endif
  50.